package com.googlecode.nacl_optimizer.model;

/**
 * Wrapper for instructions of non-optimized binary program
 * 
 * @author kornevgen
 */
public class Instruction
{
	protected final int length;
	protected final Object source_instruction;
	private final String name;
	private final String label;
	
	/**
	 * 
	 * @param length               in bytes
	 * @param name                 `code of operation'
	 * @param label                empty string or text label of this instruction in binary
	 * @param source_instruction   some representation of this instruction
	 */
	public Instruction( int length, String name, String label, Object source_instruction )
	{
		this.length = length;
		this.name = name;
		this.source_instruction = source_instruction;
		this.label = label;
	}
	
	/**
	 * length of instruction in bytes (cop plus arguments)
	 * @return
	 */
	public int getLength()
	{
		return length;
	}
	
	/**
	 * instruction as in source program (before optimization)
	 * @return
	 */
	public Object getSourceInstruction()
	{
		return source_instruction;
	}

	@Override
	public String toString()
	{
	    if ( source_instruction == null )
	        return "<" + length + "> instr";
	    else
	        return "<" + length + "> " + source_instruction.toString();
	}

    public String getName()
    {
        return name;
    }

    public String getLabel()
    {
        return label;
    }
}
